package com.hqd.test.xml.custom;

import com.hqd.ch03.v7.config.BeanDefinition;
import com.hqd.ch03.v7.reader.xml.parse.BeanDefinitionDecorator;
import com.sun.org.apache.xerces.internal.dom.DeferredAttrNSImpl;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Node;

public class SchoolBeanDefinitionDecorator implements BeanDefinitionDecorator {
    @Override
    public BeanDefinition decorate(Node node, BeanDefinition definition) {
        if (node instanceof DeferredAttrNSImpl
                && StringUtils.equalsIgnoreCase(node.getLocalName(), "school")) {
            DeferredAttrNSImpl attrNS = (DeferredAttrNSImpl) node;
            definition.getProperties()
                    .addProperty(attrNS.getLocalName(), attrNS.getValue());
        }
        return definition;
    }
}